package org.fireflow2.designer.eclipse.properties.datafield;

import org.eclipse.gef.editparts.AbstractEditPart;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.fireflow2.designer.eclipse.modelwrapper.basic.DataFieldWrapper;

public class DataFieldAttributePropertySection extends AbstractPropertySection {
	private AbstractEditPart editPart = null;
	private DataFieldWrapper modelWrapper = null;
	private DataFieldAttributeEditPanel panel  = null;
	
	public void createControls(final Composite parent,
			TabbedPropertySheetPage aTabbedPropertySheetPage) {
		super.createControls(parent, aTabbedPropertySheetPage);

		Composite composite = getWidgetFactory()
				.createFlatFormComposite(parent);

		panel = new DataFieldAttributeEditPanel();
		panel.createControl(composite, this.getWidgetFactory());
	}
	@Override
	public void refresh() {
		super.refresh();
		if (panel!=null){
			panel.refresh();
		}
	}

	@Override
	public void setInput(IWorkbenchPart part, ISelection selection) {
		super.setInput(part, selection);
		Object obj = ((IStructuredSelection) selection).getFirstElement();
		if (obj instanceof AbstractEditPart) {
			editPart = (AbstractEditPart) obj;
			modelWrapper = (DataFieldWrapper) editPart.getModel();
			panel.setModelWrapper(modelWrapper);
		}
	}	
}
